package t2.server;

import java.util.HashMap;
import java.util.Map;

public class ATcmdMap {


    private Map<String, java.lang.reflect.Method> map = new HashMap<String, java.lang.reflect.Method>();


    @SuppressWarnings({ "rawtypes", "unchecked" })
    private ATcmdMap() {
        /* The following class declarations are used to specify the type of data which
         * the method called by 'getDeclaredMethod' expects as input parameters. 
         * http://www.mkyong.com/java/how-to-use-reflection-to-call-java-method-at-runtime/ */
        Class[] paramIntAry = new Class[1];
        paramIntAry[0] = int[].class;


        try {
            Class byteUtilsClass = Class.forName("com.rapplogic.xbee.util.ByteUtils");

            /* Add keys and values to the map.  Keys are the AT commands, and the values
             * are the corresponding most appropriate method for handling the response. */
            map.put("NI", byteUtilsClass.getDeclaredMethod("toString", paramIntAry));
            map.put("PL", byteUtilsClass.getDeclaredMethod("convertMultiByteToInt", paramIntAry));
            map.put("SH", byteUtilsClass.getDeclaredMethod("toBase16", paramIntAry));
            map.put("SL", byteUtilsClass.getDeclaredMethod("toBase16", paramIntAry));
            map.put("NC", byteUtilsClass.getDeclaredMethod("convertMultiByteToInt", paramIntAry));
            map.put("AO", byteUtilsClass.getDeclaredMethod("toBase16", paramIntAry));
            map.put("MY", byteUtilsClass.getDeclaredMethod("toBase16", paramIntAry));
            map.put("MP", byteUtilsClass.getDeclaredMethod("toBase16", paramIntAry));
            map.put("ND", byteUtilsClass.getDeclaredMethod("toString", paramIntAry));


        }
        catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        catch (NoSuchMethodException e) {
            e.printStackTrace();
        }
        catch (SecurityException e) {
            e.printStackTrace();
        }
    }

    private static ATcmdMap instance = new ATcmdMap();

    public static ATcmdMap getInstance() {
        return instance;
    }

    public Map<String, java.lang.reflect.Method> getMap() {
        return map;
    }

    public void setMap(Map<String, java.lang.reflect.Method> map) {
        this.map = map;
    }
}
